from sqlalchemy import Column, String, DateTime, Text
from sqlalchemy.types import CHAR
from database import Base
import uuid
from datetime import datetime
from pydantic import BaseModel
from typing import Optional


class Project(Base):
    __tablename__ = "projects"

    # For SQLite compatibility, use CHAR(32) to store UUID as string
    id = Column(CHAR(32), primary_key=True, default=lambda: str(uuid.uuid4()).replace('-', ''))
    title = Column(String, nullable=False)
    description = Column(Text)
    created_at = Column(DateTime, default=datetime.utcnow)
    updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)


class ProjectCreate(BaseModel):
    title: str
    description: Optional[str] = None


class ProjectUpdate(BaseModel):
    title: Optional[str] = None
    description: Optional[str] = None
